import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
  },
  // 指定入口文件
  root: './src',
  // 防止vite与tauri的热更新冲突
  clearScreen: false,
  // Tauri使用固定端口，这样它就不会每次都随机选择一个端口
  server: {
    port: 1420,
    strictPort: true,
  },
  // 为了使Tauri能够正确工作，需要使用相对路径
  build: {
    outDir: '../dist',
    target: 'modules',
    minify: 'esbuild',
    sourcemap: false,
    rollupOptions: {
      cache: false,
      external: [
        '@tauri-apps/api',
        '@tauri-apps/api/core',
        '@tauri-apps/plugin-dialog',
        '@tauri-apps/plugin-fs',
        '@tauri-apps/plugin-shell'
      ]
    },
  },
  optimizeDeps: {
    exclude: [
      '@tauri-apps/api',
      '@tauri-apps/api/core',
      '@tauri-apps/plugin-dialog',
      '@tauri-apps/plugin-fs',
      '@tauri-apps/plugin-shell',
    ],
  },
});
